package day12;

import java.util.Scanner;

//类型转换异常
public class demo3 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.print("1.two  2.three:");
        int n=sc.nextInt();
        One one=null;
        if (n==1){
            one=new Two();
        }else {
            one =new Three();
        }
        //如果有需要，需要将one转换成子类？
        if (one instanceof Two){
            Two t=(Two)one;
            System.out.println("转换为Two对象！"+t);
        }else if (one instanceof Three){
            Three t=(Three)one;
            System.out.println("转换为Three对象！"+t);
        }

    }
}

class One{}
class Two extends One{}
class Three extends One{}
